/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kedacom.demo.spring.aware;

import java.util.logging.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.stereotype.Component;

/**
 *
 * @author xiaojinghai
 */
@Component
public class SpringApplicationContextAware implements ApplicationContextAware {

    private static final Logger logger = Logger.getLogger(SpringApplicationContextAware.class.getName());
    private ApplicationContext applicationContext;

    public ApplicationContext getApplicationContext() {
        return this.applicationContext;
    }

    public void publishEvent(ApplicationEvent event) {
        this.applicationContext.publishEvent(event);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
        logger.info("获取到Spring应用容器类:" + this.getClass().getName());
    }
}
